﻿using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class SheetExtRecord : BiffRecord
    {
        private FrtHeader frtHeader;
        private int icvPlain;
        private SheetExtOptional sheetExtOptional;

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            this.frtHeader = new FrtHeader();
            frtHeader.Read(context.Reader);
            Contract.Assert(frtHeader._rt == 0x0862);
            var cb = context.ReadUInt32();
            this.icvPlain = context.ReadByte() & 0xCF;
            context.ReadBytes(3);
            if (cb == 0x00000028)
            {
                sheetExtOptional = new SheetExtOptional();
                sheetExtOptional.Read(context.Reader);
            }
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.SheetExt; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            throw new System.NotImplementedException();
        }
    }

    internal class SheetExtOptional
    {
        private byte icvPlain12A;
        private byte[] bReserved;
        private byte[] color;

        public void Read(BinaryReader reader)
        {
            this.icvPlain12A = reader.ReadByte();
            this.bReserved = reader.ReadBytes(3);
            this.color = reader.ReadBytes(16);
        }
    }
}